package com.jeeplus.modules.guide.service;

import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.guide.entity.YmbcsLabel;
import com.jeeplus.modules.guide.entity.YmbcsMatter;
import com.jeeplus.modules.guide.entity.YmbcsMatterBszn;
import com.jeeplus.modules.guide.mapper.YmbcsMatterMapper;
import com.jeeplus.modules.guide.utils.DataUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
@RequiredArgsConstructor
@Transactional
@Slf4j
public class YmbcsMatterService {
    private final YmbcsMatterMapper ymbcsMatterMapper;
    public List<YmbcsMatter> ymbcsMatterList(String searchWords,String version){
        if(StringUtils.isNotBlank(searchWords))searchWords="%"+searchWords+"%";
        return ymbcsMatterMapper.ymbcsMatterList(searchWords,version);
    }

    public List<YmbcsLabel> ymbcsMatterType(){
        return ymbcsMatterMapper.ymbcsMatterType();
    }

    public List<YmbcsMatterBszn> ymbcsStreeList(String matterName, String version){
        matterName = matterName+"%";
        return ymbcsMatterMapper.ymbcsStreeList(matterName,version);
    }
    public List<Map<String,Object>> ymbcsMaterialList(String idcard){
        return ymbcsMatterMapper.ymbcsMaterialList(idcard);
    }
    public String ymbcsMaterialDo(String oid){
        return ymbcsMatterMapper.ymbcsMaterialDo(oid);
    }

    public List<Map<String,Object>> ymbcsMyMaterialList(String loginName,String oid){
        return ymbcsMatterMapper.ymbcsMyMaterialList(loginName,oid);
    }
    public List<YmbcsMatter> ymbcsMatterListOnline(String searchWords,String version){
        if(StringUtils.isNotBlank(searchWords))searchWords="%"+searchWords+"%";
        return ymbcsMatterMapper.ymbcsMatterListOnline(searchWords,version);
    }
    public List<String> ymbcsMatterListOnlineByName(String version,String matterName){
        return ymbcsMatterMapper.ymbcsMatterListOnlineByName(version,matterName);
    }
    public List<HashMap<String,String>> matterSWList(String searchWords){
        if(StringUtils.isNotBlank(searchWords))searchWords="%"+searchWords+"%";
        return ymbcsMatterMapper.matterSWList(searchWords);
    }
    @Transactional(readOnly = false)
    public int intoRC(String name,String jsonValue,String matterName,String loginName){
        return ymbcsMatterMapper.intoRC(UUID.randomUUID().toString(),name,jsonValue,matterName, DateUtils.getDateTime(),loginName);
    }
    public String selectRC(String loginName,String name){
        return ymbcsMatterMapper.selectRC(loginName,name);
    }
    @Transactional(readOnly = false)
    public int updateRC(String id,String jsonValue){
        return ymbcsMatterMapper.updateRC(id,jsonValue);
    }

    public String findRCById(String id){
        return ymbcsMatterMapper.findRCById(id);
    }

    @Transactional(readOnly = false)
    public void  updateListFR(){
        //超期法人数据
        List <Map <String, String>> maps = ymbcsMatterMapper.cqListFR();
        for(Map <String, String> m : maps){
            ymbcsMatterMapper.updateListFR(m.get("idcard"),m.get("loginName"));
        }
        //超期经办人数据
        maps = ymbcsMatterMapper.cqListJBR();
        for(Map <String, String> m : maps){
            ymbcsMatterMapper.delListFR(m.get("idcard"),m.get("loginName"));
        }
    }
    public String findmaterialsUrl(String idcard){
        return ymbcsMatterMapper.findmaterialsUrl(idcard);
    }

    public List<HashMap<String,String>> findMaterialsListName(){
        return ymbcsMatterMapper.findMaterialsListName();
    }

    @Transactional(readOnly = false)
    public void   intomateriallist(String oid,String mattername,String materialname){
        ymbcsMatterMapper.intomateriallist(oid,mattername,materialname);
    }
}
